package me.send.business.service.mapper;

import java.util.List;
import java.util.Map;

import me.send.business.service.BaseMapper;
import me.send.business.service.pojo.Comment;
import me.send.business.service.pojo.User;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;


public abstract interface CommentMapper extends BaseMapper {

	/**
	 * 递归查询一下 分页查询 2015年6月11日17:46:12
	 * 
	 * 根据下面的pcommentid 查询出来
	 * 
	 */

	@Select(value = "select commentid,context,substring(createtime,1,16) as sendtime,userid,orderid,pcommentid from comment where orderid = #{orderid} order by createtime desc limit #{page.start},#{page.size}")
	@Results( {	
			@Result(property = "commentid", column = "commentid"),
			/** 根据页面的orderID 查询order的详细信息 2015年6月12日08:58:58 * */
			@Result(property = "pcommentid", column = "pcommentid"),
			/** 定义 父类的节点 * */
			@Result(property = "pcomment", column = "pcommentid", one = @One(select = "one_comment_commentid")),
			/** 获取到父类的属性 调用 根据id查询 单个信息的数据 * */
			@Result(property = "userid", column = "userid"),
			@Result(property = "user", column = "userid", one = @One(select = mapper_usermapper
					+ "one_user_userid"))
	/** 获取到发送评论的用户的信息 2015年6月12日11:35:02 * */
	})
	public abstract List<Map<String, Object>> list_page_orderid(
			Map<String, Object> param);

	/**
	 * 查看该订单的 评论数量 2015年6月12日15:17:26
	 */
	@Select(value="select count(1) as total from comment where orderid = #{orderid}")
	public abstract int count_comment_orderid(int orderid);
	
	/**
	 * 增加评论的接口  用户登录的情况下 给具体的订单评论 
	 * 
	 * 2015-6-12 15:29:33
	 */
	@Insert(value="insert into comment(context,createtime,lookstatus,userid,orderid,pcommentid) values(#{context},#{createtime},#{lookstatus},#{userid},#{orderid},#{pcommentid})")
	public abstract void comment_save(Comment comment);
	
	/**
	 * 
	 * 根据订单号码 查询单个对象 2015年6月12日09:03:44
	 * 
	 */
	@Select(value = "select context,substring(createtime,1,16) as sendtime,userid,orderid,pcommentid from comment  where commentid = #{pcommentid} order by createtime desc")
	@Results( {
			@Result(column = "userid", property = "userid"),
			@Result(column = "userid", property = "user", one = @One(select = mapper_usermapper
					+ "one_user_userid")) })
	public abstract Map<String, Object> one_comment_commentid(Integer pcommentid);

	@Select(value = "select * from comment ")
	public abstract List<Map<String, Object>> list_page_userid(
			Map<String, Object> param);

	
	@Select(value = "SELECT u.isvAccountId,u.userid FROM `comment` c "
			+ "LEFT JOIN orders o ON c.orderid = o.orderid "
			+ "LEFT JOIN `user` u ON u.userid = o.userid "
			+ "WHERE c.commentid = #{commnetid}")
	public abstract User getUserByCommentParentId(int commnetid); 
}
